import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_localizations/flutter_localizations.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yi_shop/route/index.dart';
import 'package:yi_shop/utils/colors.dart';
import 'package:yi_shop/utils/styles.dart';

import 'auth/index.dart';

void main() {
  SystemChrome.setSystemUIOverlayStyle(const SystemUiOverlayStyle(
    statusBarIconBrightness: Brightness.light,
    statusBarColor: Colors.transparent,
  ));
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(375, 667),
      minTextAdapt: true,
      splitScreenMode: true,
      useInheritedMediaQuery: true,
      ensureScreenSize: true,
      builder: (context, child) {
        return buildGetApp(context);
      },
    );
  }

  Widget buildGetApp(BuildContext context) {
    return GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: '易店',
      theme: ThemeData(
          colorScheme: ColorScheme.fromSeed(
              seedColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF048)),
          useMaterial3: true,
          fontFamilyFallback: const [
            'PingFang_SC_Regular',
            'PingFang_SC_Semibold',
            'PingFang_SC',
            'sans-serif'
          ],
          fontFamily: StylesUtils.defaultFamily,
          badgeTheme: BadgeThemeData(
              backgroundColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF048)),
          appBarTheme: AppBarTheme(
            iconTheme: IconThemeData(color: Colors.white, size: 20.w),
            centerTitle: true,
            titleSpacing: 0,
            titleTextStyle: StylesUtils.customTextStyle(
                fontSize: StylesUtils.fontSize16, fontWeight: FontWeight.w700),
            elevation: 0,
            surfaceTintColor: Colors.transparent,
            backgroundColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF048),
            systemOverlayStyle: SystemUiOverlayStyle.light,
          ),
          iconTheme: IconThemeData(color: Colors.white, size: 20.w),
          iconButtonTheme: IconButtonThemeData(
            style: ButtonStyle(
                padding: const WidgetStatePropertyAll(EdgeInsets.zero),
                alignment: Alignment.center,
                textStyle: WidgetStateProperty.all(StylesUtils.customTextStyle())),
          ),
          scaffoldBackgroundColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF2f2),
          dialogBackgroundColor: Colors.black54),
      darkTheme: ThemeData(
        brightness: Brightness.light,
      ),
      themeMode: ThemeMode.system,
      initialRoute: RoutePath.home,
      getPages: RoutePath.pages,
      transitionDuration: const Duration(milliseconds: 500),
      defaultTransition: Transition.cupertino,
      locale: const Locale('zh', 'CN'),
      fallbackLocale: const Locale('zh', 'CN'),
      supportedLocales: const [Locale('zh', 'CN'), Locale('en', 'US')],
      localizationsDelegates: const [
        RefreshLocalizations.delegate,
        GlobalMaterialLocalizations.delegate,
        GlobalWidgetsLocalizations.delegate,
        GlobalCupertinoLocalizations.delegate,
      ],
      navigatorObservers: [AuthGuard()],
    );
  }
}
